Reporting

The VMWare vCloud Director allows you to retrieve reporting metrics through its API, as described in the VMware vCloud Director Virtual Machine Metrics documentation.

The following metrics are available:

Metric name Type Unit Description
cpu.usage.maximum rate percent view of this virtual machine's maximum actively used CPU as a percentage of total available. Includes all cores in all sockets.
cpu.usagemhz.average rate megahertz Host view of this virtual machine's average actively used CPU as a raw measurement . Includes all cores in all sockets.
mem.usage.average absolute percent Memory used by this virtual machine as a percentage of total configured memory.
disk.used.latest absolute kilobytes Storage used by all virtual hard disks.
disk.provisioned.latest absolute kilobytes Storage space allocated to this virtual hard disk in the containing organization virtual data center.

The script below is an example of how metrics can be retrieved and directly written into a .csv file.

Prerequisite

Please be aware that the script can only be executed with an API user. If you don't have an API user, please follow the steps as described here.

Script

Copy the following script into a text file, save it as a .ps1 file (e.g. MyScript.ps1) and fill in the following missing variables:

  • $vOrg = ''
  • $orgUserName = ''
  • $orgAdminPW = ''
  • $csvfile = ''
import-module VMware.VimAutomation.Cloud

$vCdPlatform = 'datacenter.swisscomcloud.com'
$vOrg = ''
$orgUserName = ''
$orgAdminPW = ''
$csvfile = ''

$vcdConn = Connect-CIServer -Server $vCdPlatform -Org $vOrg  -User $orgUserName   -Password  $orgAdminPW

if([System.IO.File]::Exists($csvfile)){
    $csv_appent = $true
} else {
    $csv_appent = $false
}

$result_array = New-Object System.Collections.Generic.List[System.Object]

$ovdc_list = Get-OrgVdc
ForEach ($ovdc in $ovdc_list) {
    $vApp_list = $ovdc | Get-CIVApp
    ForEach ($vApp in $vApp_list){
        $vm_list = $vApp.ExtensionData.Children.Vm
        if ($vm_list) {
            ForEach($vm in $vm_list) {
                if ($vm.Status -eq 4) {
                    Write-Host "get metrics for VM $($vm.Name) in vApp $($vApp.Name)  in OvDC: $($ovdc.Name)"
                    $metrics = $vm.GetMetricsCurrent()
                    $ThisRow = "" | select datetime,Org,OvDC,vApp,VM,cpu.usage.maximum,cpu.usagemhz.average,mem.usage.average,disk.used.latest,disk.provisioned.latest
                    $ThisRow.Org = $vOrg
                    $ThisRow.OvDC = $ovdc.Name
                    $ThisRow.vApp = $vApp.Name
                    $ThisRow.VM = $vm.Name
                    $ThisRow.datetime = Get-Date -format s
                    ForEach ($metrics_param in $metrics.Metric) {
                        $param_name_list += $metrics_param.Name
                        if ($metrics_param.Name.StartsWith('cpu.usage.aver')){

                       } else {
                            $ThisRow.$($metrics_param.Name) = $metrics_param.Value
                        }
                    }
                    $result_array.add($ThisRow)
                    if ($csv_appent) {
                        Export-Csv $csvfile -inputobject $ThisRow -append -Force
                    }
                } else {
                    Write-Host "VM $($vm.Name) is not powered on  in vApp $($vApp.Name)  in OvDC: $($ovdc.Name)"
                }
            }
        }

    }
}

if (!$csv_appent) {
    $result_array | Export-Csv -Path $csvfile -NoTypeInformation
}

Run

By running the script, the performance data of your vOrg, specified in $vOrg = '', will be written into the .csv file as defined in $csvfile = ''.

If you would like to retrieve performance data continously, you can create a task in the Task Scheduler:

powershell -File myScript.ps1 -WindowStyle Hidden

Note:

  • As a best practice we recommend to run the script in 30 or 60 min intervals, for a continuous performance data measurement.
  • Regarding availability of the vCloud Director API, please refer to the service availability of the Self Service Portal, as described in the Service Description.

results matching ""

    No results matching ""